/******************************************************************
 * 2017 (C)   IST Copyright. All Rights Reserved.
 * File name    : time_out.c
 * Author       : yxy
 * Version      : V1.0
 * Date         : 2017
 * Description  :
 * Function List:
 * History      :
*******************************************************************/

#include "time_out.h"


static uint32_t cycle_counter = 0;

void Timeout_CountAdd(void)
{
    cycle_counter++;
}

uint32_t GetSystemClock(void)
{
    return cycle_counter;
}

void Timeout_Start(TimeOut_HandleTypeDef * timeout, uint32_t length){
    timeout->Name = length;
    timeout->StartValue = cycle_counter;
}

void Timeout_Stop(TimeOut_HandleTypeDef * timeout){
    timeout->Name = 0x00;
}

uint32_t Timeout_IsNotStart(TimeOut_HandleTypeDef * timeout){
    if(timeout->Name)
        return 0x00;
    else
        return 0xffff;
}

uint32_t Timeout_IsStart(TimeOut_HandleTypeDef * timeout){
    if(timeout->Name)
        return 0xffff;
    else
        return 0x00;
}

uint32_t Timeout_IsTimeOut(TimeOut_HandleTypeDef * timeout){
    if(timeout->Name)
        if((cycle_counter - timeout->StartValue) >= timeout->Name){
            Timeout_Stop(timeout);
            return 0xffff;
            }
    return 0x00;
}



